from __future__ import absolute_import

from . import token
from scopt.util import message as msg_util
from scopt.util.message_types import STRING


@token(version='0.1',
       token={'type': 'security.invalidate_token',
              'value': STRING(required=True)})
def handle(data_packet, registry):
    security_token = msg_util.get_security_token(data_packet)
    registry.update('users',
                    values={'token': None},
                    where=[['users.token', security_token['value']]])
    data_packet = msg_util.ok_response(data_packet, handle)
    return msg_util.finish_data_packet(data_packet)
